package com.sz.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sz.mapper.ProblemMapper;
import com.sz.model.PageBeanType;
import com.sz.model.QuestionType;
import com.sz.service.IProblemType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProblemTypeImpl implements IProblemType {
    @Autowired
    private ProblemMapper problemMapper;
    @Override
    public PageBeanType<QuestionType> getAllQuestion(int index, int size) {
        PageHelper.startPage(index, size); // 开始分页;
        List<QuestionType> list = problemMapper.getAllQuestion();
        Page<QuestionType> plist = (Page<QuestionType>) list;
        PageBeanType<QuestionType> pb = new PageBeanType<>(
                plist.getTotal(),
                plist.getResult(),
                plist.getPageSize(),
                plist.getPages(),
                plist.getPageNum()
        );
        return pb;
    }

    @Override
    public PageBeanType<QuestionType> getQuestion(int index,int size,String question) {
        PageHelper.startPage(index, size); // 开始分页;
        List<QuestionType> list = problemMapper.getQuestion(question);
        Page<QuestionType> plist = (Page<QuestionType>) list;
        PageBeanType<QuestionType> pb = new PageBeanType<>(
                plist.getTotal(),
                plist.getResult(),
                plist.getPageSize(),
                plist.getPages(),
                plist.getPageNum()
        );
        return pb;
    }
}
